﻿using System;
using System.Collections.Generic;
using System.Text;
using Scripting;

namespace UserScripts
{
    public class Attack : ScriptBase
    {
        static void Main(Actor attacker, Actor target)
        {
            // attacker variables
            CustomAttributes ca = new CustomAttributes();
            int attackerDex = ca.GetCustomAttributes(attacker, "Dexterity");
            int attackerDexStep = ca.GetStepNumber(attackerDex);
            int attackerStr = ca.GetCustomAttributes(attacker, "Strength");
            int attackerStrStep = ca.GetStepNumber(attackerStr);
            int attackerUCRank = attacker.GetAbilityLevel("UnarmedCombat");
            int attackerInitStep = ca.GetInitStep(attacker);


            // target variables
            int targetPhysDef = ca.GetCustomAttributes(target, "PhysicalDefense");


            // set the combat variables
            int targetNumber = targetPhysDef;
            int attackStep = attackerUCRank + attackerDexStep;

            // attack test
            StepEval roll = new StepEval();
            int attackRoll = roll.GetRoll(attackStep);
            attacker.Animate("Default Attack", 1, true);
            attacker.Output("Your attack roll was " + attackRoll + ".");
            if (attackRoll >= targetNumber)
            {
                target.Animate("Hit 1", 1, true);
                int damageRoll = roll.GetRoll(attackerStrStep);
                target.CreateFloatingNumber(damageRoll, System.Drawing.Color.Red);
                target.SetAttribute("Health", target.GetAttribute("Health") - damageRoll);
                attacker.Output("You did " + damageRoll + " damage to " + target.Name + ".");
            }
            else
            {
                attacker.Output("You missed " + target.Name + ".");
            }
        }    
    }
}
